const yargs = require('yargs');
const path = require('path');
const build = require('./build');
const { log } = require('../../log');

// 
const argv = yargs
  .option('templatePath', {
    alias: 't',
    description: '需要打包的We码模板文件地址',
    type: 'string',
  })
  .option('debug', {
    alias: 'd',
    description: '是否为调试版本，默认false。如果设置为true，将展示vsconsole和不压缩代码，便于调试',
    type: 'boolean',
  })
  .option('environment', {
    alias: 'e',
    description: '设置环境变量process.env.APP_ENV，可选值为：gamma，uat 和 production',
    type: 'string',
  })
  .help()
  .alias('help', 'h')
  .argv;

process.env.LOCAL_TEST = true;

const cwdPath = process.cwd();
const runtimePath = path.join(__dirname, '../../');
// 默认当前执行目录
let appPath = path.resolve(cwdPath);
let env = 'production'; // can be gamma, uat or production
let debug = false;

if(argv.templatePath) {
  appPath = path.resolve(cwdPath, argv.templatePath);
}

log('runtimePath:', runtimePath);
if(argv.environment) {
  env=argv.environment;
}
log(`Template file path:${appPath}`);
log(`Environment:${env}`);
log(`Debug mode:${debug}`);
log(`Runtime path:${runtimePath}`);

build({
  env: {
    WECODE_ENV: env,
    WECODE_DEBUG: debug,
    WECODE_APP_PATH: appPath,
    RUNTIME_PATH: runtimePath
  }
});
